Anti-shake method for panoramic video, and portable terminal

ABSTRACT

The present invention provides an anti-shake method for a panoramic video, which comprises: obtaining, in real time, an output video frame, a fisheye image corresponding thereto, a pixel timestamp in the video frame, and a corresponding camera gyroscope timestamp; synchronizing the pixel timestamp in the video frame with the corresponding camera gyroscope timestamp, and calculating a rotation matrix of the camera movement in the camera gyroscope timestamp; smoothing the camera movement and establishing a coordinate system of a smooth trajectory; correcting the fisheye image distortion; and rendering the fisheye image by means of forward rendering to generate a stable video. According to the present invention, the rolling shutter distortion of a panoramic video sequence can be corrected, the image distortion caused by the rolling shutter of a CMOS can be corrected, and the rolling shutter is eliminated, thereby achieving a better anti-shake effect of a video image.

FIELD OF THE INVENTION

The present invention relates generally to the field of video processing, and particularly relates to an anti-shake method for a panoramic video and a portable terminal.

BACKGROUND OF THE INVENTION

CMOS and CCD sensors are two types of image sensors that are currently commonly used. Both use photodiodes for photoelectric conversion to convert images into digital data. The main difference is the way in which digital data is transmitted.

The charge data of each pixel in each line of the CCD sensor will be transferred to the next pixel in turn, and be outputted from the bottom thereof, then be amplified and outputted by the amplifier at the edge of the sensor; while in the CMOS sensor, each pixel will be adjacent to one amplifier and an A/D conversion circuit, and data is outputted in a way similar to a memory circuit.

Generally, CMOS cameras use rolling shutter mode to obtain fisheye images through progressive exposure.

CMOS chips share the workload through many parallel A/Ds, but the entire array in the sensor must be converted one line at a time, which results in a small time delay between the readings of each line. Each individual line is usually able to start the exposure of the next frame when the readout of the previous frame is completed. Although the speed is very fast, the time delay between the readings of each line will be converted into the delay between the start of the exposure of each line, exposure of each line will not happen at the same time. The result is that each line in the frame will be exposed for the same time length, but the exposure will start at a different time point. Two frames are allowed to overlap exposure, and the final frame rate depends on the speed at which the scrolling readout process can be completed.

Such exposure mode causes a time difference between different lines of the same frame of image. If a handheld panoramic camera is used to shoot, when moving at high speeds, a jelly effect will occur due to the progressive exposure of the CMOS camera. The jelly effect is a problem that has not been well solved, especially for a VR panoramic video, and the anti-shake effect of video is poor.

SUMMARY OF THE INVENTION

The problem solved by the present invention is to provide an anti-shake method for a panoramic video, a computer-readable storage medium and a portable terminal, which aims to solve the jelly effect caused by the shaking of the picture due to the rolling shutter mode of the CMOS chip, and the poor anti-shake effect of the camera.

According to a first aspect, the present invention provides an anti-shake method for a panoramic video, comprises steps of:

obtaining, in real time, an output video frame, a fisheye image corresponding to the output video frame, a timestamp of the pixel in the video frame, and a corresponding camera gyroscope timestamp;

synchronizing the timestamp of the pixel in the video frame with the corresponding camera gyroscope timestamp, and calculating a rotation matrix of the camera movement in the camera gyroscope timestamp;

smoothing the camera movement and establishing a coordinate system of a smooth trajectory;

correcting the fisheye image distortion; and

rendering the fisheye image by means of forward rendering to generate a stable video.

According to a second aspect, the present invention provides an anti-shake method for a panoramic video, comprises steps of:

S201, obtaining, in real time, an output video frame, a fisheye image corresponding to the output video frame, a timestamp of the pixel in the video frame, and a corresponding camera gyroscope timestamp;

S202, synchronizing the timestamp in the video frame to the camera gyroscope acquisition system, and calculating a rotation matrix of the camera movement in the timestamp of the pixel in the current video frame as the approximate rotation matrix of the camera when collecting the current pixel;

S203, projecting the output video frame pixels to the corresponding grid points of the spherical model, and using the approximate rotation matrix to rotate the corresponding grid points of the spherical model to the grid points in the sensor coordinate system; using the fisheye image distortion correction method to establish the relationship between the grid points in the sensor coordinate system and the pixels in the fisheye image to obtain approximate reverse-mapping pixels;

S204, calculating the camera gyroscope timestamp of the approximate reverse-mapping pixels in the fisheye image, obtaining the accurate rotation matrix of the camera when collecting the current pixel, and using the accurate rotation matrix to rotate the corresponding grid points of spherical model again to obtain the second grid points in the sensor coordinate system;

S205, using the fisheye image distortion correction method to establish the relationship between the second grid points in the sensor coordinate system and the pixels in the fisheye image to obtain accurate pixels in the fisheye image, and using the mapping relationship between the output video frame pixels and the accurate pixels in the fisheye image, rendering the fisheye image in reverse rendering to generate a stable video.

According to a third aspect, the present invention provides a computer-readable medium that stores a computer program or computer programs, which when being executed by a processor or processors, cause the processor or processors to perform steps of the above-mentioned anti-shake method for a panoramic video.

According to a fourth aspect, the present invention provides a portable terminal, comprising:

one or more processors; a memory; and one or more computer programs where the one or more computer programs are stored in the memory and are configured to be executed by the one or more processors, and when executed by the one or more processors, cause the one or more processors to perform the above-mentioned anti-shake method for a panoramic video.

In the present invention, based on the timestamp of the pixel in the video frame, the fisheye image is pixel by pixel converted into the coordinate system of the smooth trajectory using the rotation matrix of the camera motion under the timestamp of the current video frame pixel in real time, and then rendered and output; thereby the distortion of the rolling shutter of the panoramic video sequence can be corrected. The invention can correct the image distortion caused by the CMOS rolling shutter and eliminate the jelly effect, and achieve better video image anti-shake effect;

Further, in the present invention, according to the timestamp of the video frame pixel, calculating the rotation matrix of the camera movement under the timestamp of the current video frame pixel as the approximate rotation matrix of the camera when collecting the current pixel, projecting the output video frame pixels to the corresponding grid points of the spherical model, and using the approximate rotation matrix to rotate the corresponding grid points of the spherical model to the grid points in the sensor coordinate system; using the fisheye image distortion correction method to establish the relationship between the grid points in the sensor coordinate system and the pixels in the fisheye image to obtain approximate reverse mapping pixels, calculating the camera gyroscope timestamp of the approximate reverse-mapping pixels in the fisheye image, obtaining the accurate rotation matrix of the camera when collecting the current pixel, and using the accurate rotation matrix to rotate the corresponding grid points of spherical model again to obtain the second grid points in the sensor coordinate system; using the fisheye image distortion correction method to establish the relationship between the second grid points in the sensor coordinate system and the pixels in the fisheye image to obtain accurate pixels in the fisheye image, and using the mapping relationship between the output video frame pixels and the accurate pixels in the fisheye image, rendering the fisheye image in reverse rendering to generate a stable video. Thereby, the distortion of the rolling shutter of the panoramic video sequence can be corrected. The invention can correct the image distortion caused by the CMOS rolling shutter and eliminate the jelly effect, thereby achieve a better video image anti-shake effect.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a flowchart of an anti-shake method for a panoramic video in accordance with a first embodiment of the present invention;

FIG. 2 is a schematic diagram of the timestamp of the scan line sequence of the CMOS camera in accordance with the first embodiment of the present invention;

FIG. 3 is a mapping process diagram of a forward mapping rendering method in the anti-shake method for a panoramic video in accordance with the first embodiment of the present invention;

FIG. 4 is a flowchart of the anti-shake method for a panoramic video in accordance with a second embodiment of the present invention;

FIG. 5 is a mapping process diagram of a backward mapping rendering method in the anti-shake method for a panoramic video in accordance with the second embodiment of the present invention; and

FIG. 6 is a schematic structural diagram of a portable terminal in accordance with a fourth embodiment of the present invention.

DETAILED DESCRIPTION OF THE INVENTION

The foregoing objects, technical solutions and advantages of the invention will be much clearer from the following detail description taken with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.

In order to explain the technical solutions of the present invention, the following will be described by specific embodiments.

First Embodiment

Referring to FIG. 1, an anti-shake method for a panoramic video provided in the first embodiment of the present invention comprising the following steps:

S101, obtaining, in real time, an output video frame, a fisheye image corresponding to the output video frame, a timestamp of the pixel in the video frame, and a corresponding camera gyroscope timestamp;

in the first embodiment of the present invention, S101 may specifically comprise the following steps:

S1011, obtaining the output video frame and the fisheye image corresponding to the output video frame;

S1012, obtaining the timestamp t_(frame) ^(k) ^(p(x,y)) of the pixel p(x, y) in the k video frame in the time axis of a video frame acquisition system, where k is a natural number; and

S1013, obtaining the gyroscope timestamp t_(gyro) ^(k) ^(p(x,y)) in the time axis of the corresponding camera gyroscope acquisition system.

S102, synchronizing the timestamp of the pixel in the video frame with the corresponding camera gyroscope timestamp, and calculating a rotation matrix of the camera movement in the camera gyroscope timestamp;

referring to FIG. 2, in the first embodiment of the present invention, S102 may specifically comprise the following steps:

S1021, calculating the timestamp t_(frame) ^(k) ^(p(x,y)) of the pixel p(x, y) in the k video frame by formula (1):

$\begin{matrix} {{t_{frame}^{k_{p{({x,y})}}} = {t_{frame}^{k} + {\frac{\Delta t}{H}y} - {\frac{1}{2}\Delta \; t}}};} & (1) \end{matrix}$

in formula (1), t_(frame) ^(k) ^(p(x,y)) is the timestamp of the pixel at the beginning of the k video frame, Δt is a sampling time interval of the progressive scan of the video frame, and H is the number of lines of the image;

S1022, synchronizing the timestamp of the pixel in the k video frame with the camera gyroscope timestamp, a conversion relationship between the two as formula (2):

t _(gyro) ^(k) ^(p(x,y)) =ΔT ₀ +t _(frame) ^(k) ^(p(x,y))   (2)

-   -   in formula (2), ΔT₀=t_(gyro) ^(k)−t_(frame) ^(k), t_(gyro) ^(k)         is the camera gyroscope timestamp at the beginning of the k         video frame;

S1023, calculating a rotation matrix of the camera movement in the camera gyroscope timestamp at time t_(gyro) ^(k) ^(p(x,y)) by formula (3):

R _(w2s)(t _(gyro) ^(k) ^(p(x,y)) )=R _(w2g)(t _(gyro) ^(k) ^(p(x,y)) )·R _(g2s)(t _(gyro) ^(k) ^(p(x,y)) )  (3)

in formula (3), R_(w2g)(t_(gyro) ^(k) ^(p(x,y)) ) is a rotation matrix measured by a gyroscope sensor at time t_(gyro) ^(k) ^(p(x,y)) , R_(g2s)(t_(gyro) ^(k) ^(p(x,y)) ) is a rotation matrix from the calibrated gyroscope coordinate system to the camera, and R_(w2s)(t_(gyro) ^(k) ^(p(x,y)) ) is a 3*3 matrix.

S103, smoothing the camera movement and establishing a coordinate system of a smooth trajectory;

in the first embodiment of the present invention, S103 may specifically comprise the following steps:

S1031, where P^(s) representing the 3D coordinates in the camera coordinate system, let t=t_(gyro) ^(k) ^(p(x,y)) , converting the 3D coordinates P_(t) ^(w) in the world coordinate system to the 3D coordinates P_(t) ^(s) in the camera coordinate system at time t by a formula:

P _(t) ^(s) =R _(w2s)(t)·P _(t) ^(w)+{right arrow over (t ₀)}  (4)

in the formula (4), R_(w2s)(t) is a matrix of the camera coordinate system relative to the world coordinate system at time t, and {right arrow over (t₀)} is a translation amount of the two frames before and after of the video frame of the camera;

S1032, smoothing the camera movement, where setting {right arrow over (t₀)}=0 and then obtaining

${P_{t}^{w} = \frac{P_{t}^{s}}{R_{w\; 2s}(t)}};$

S1033, establishing the coordinate system P_(t)′ of the smooth trajectory, performing a 3D grid rendering processing on the coordinate system P_(t)′ of the camera's smooth trajectory by OpenGl Rendering formula: P_(t) ^(gl)=K□R_(nvp)□P_(t)′; where K is a perspective matrix, R_(nvp) is a matrix of the movement direction manually controlled, and P_(t) ^(gl) is the 3D coordinates rendered by OpenGl in the coordinate system of the smooth trajectory; and

S1034, in the coordinate system of the smooth trajectory, obtaining the minimum square difference of any pixel in P_(t)′ in the two frames before and after by a formula: min(P_(t+1)′−P_(t)′)²+(P_(t)′−P_(t) ^(w))², where P_(t)′ and P_(t+1)′ are the coordinate systems of the smooth trajectory of the two frames before and after, respectively; setting P_(t)′=P_(t+1)′=P_(t) ^(w), and obtaining the rendering formula as formula (5):

P _(t) ^(gl) =K□R _(nvp) □R _(w2s(t)) ⁻¹ □P _(t) ^(s)  (5)

calculating the 3D coordinates of the camera rendered to the coordinate system of the smooth trajectory by formula (5).

S104, correcting the fisheye image distortion.

In the first embodiment of the present invention, S104 may specifically comprise:

where let

P^(s) = P_(t_(gyro)^(k_(p(x, y))))^(s),

obtaining a panoramic expanded image of P^(s) in the camera coordinate system:

$\begin{matrix} {P^{s} = \left\{ \begin{matrix} {{\cos (u)}{\cos (v)}} \\ {{\cos (u)}{\sin (v)}} \\ {\sin (u)} \end{matrix} \right.} & (6) \end{matrix}$

in formula (6), u and v are the abscissa and ordinate of the panoramic expanded image in the camera coordinate system, respectively;

a fisheye distortion model ρ=f(θ)=θ(1+k₀θ²+k₁θ⁴+k₂θ⁶+k₃θ⁸), where θ is an incident angle of the light, k₀, k₁, k₂, and k₃ are the camera calibration coefficients, obtaining the corrected coordinates (x, y) of the fisheye image:

$\begin{matrix} \left\{ \begin{matrix} {x = {{f_{x}{\bullet\rho\bullet}\frac{P_{x}^{s}}{r}} + x_{c}}} \\ {y = {{f_{y}{\bullet\rho\bullet}\frac{P_{y}^{s}}{r}} + y_{c}}} \end{matrix} \right. & (7) \end{matrix}$

in formula (7), r=√{square root over (P_(x) ^(s2)+P_(y) ^(s2))}, θ=atan(r, P_(z) ^(s)); the point (x_(c), y_(c)) is a projection center of the sensor, x and y are the 2D coordinates of the projection position of the camera sensor respectively.

S105, rendering the fisheye image by means of forward rendering to generate a stable video.

In the first embodiment of the present invention, S105 may specifically comprise the following steps of:

establishing a correspondence between the fisheye image and the grid points of the spherical model in the camera coordinate system by means of the fisheye image distortion correction method;

generating the grid points of the spherical model in the coordinate system of the smooth trajectory by rendering; and

performing panoramic expansion of the grid points of the spherical model in the coordinate system of the smooth trajectory to generate a stable video. Where, specifically, color information can be input by interpolation, and projection can generate perspective images or asteroid images.

Referring to FIG. 3, in the first embodiment of the present invention:

A₁ corresponds to A₂, where A₁ is the coordinate in the fisheye image, A₂ corresponds to A₁, is the coordinate of the grid point of the spherical model in the camera coordinate system; A₃ corresponds to A₂, is the coordinate of the grid point of the spherical model in the coordinate system of the smooth trajectory generated by rendering; and A₄ is the coordinate point generated by the panoramic expansion projection of A₃;

Similarly, B₁ corresponds to B₂, where B₁ is the coordinate in the fisheye image, B₂ corresponds to B₁, is the coordinate of the grid point of the spherical model in the camera coordinate system; B₃ corresponds to B₂, is the coordinate of the grid point of the spherical model in the coordinate system of the smooth trajectory generated by rendering; and B₄ is the coordinate point generated by the panoramic expansion projection of B₃.

In the first embodiment of the present invention, based on the timestamp of the pixel in the video frame, the fisheye image is pixel by pixel converted into the coordinate system of the smooth trajectory using the rotation matrix of the camera motion under the timestamp of the current video frame pixel in real time, and then rendered and output; thereby the distortion of the rolling shutter of the panoramic video sequence can be corrected. The invention can correct the image distortion caused by the CMOS rolling shutter and eliminate the jelly effect, and achieve better video image anti-shake effect.

Second Embodiment

Referring to FIG. 4, an anti-shake method for a panoramic video provided in is the second embodiment of the present invention comprising the following steps:

S201, obtaining, in real time, an output video frame, a fisheye image corresponding to the output video frame, a timestamp of the pixel in the video frame, and a corresponding camera gyroscope timestamp;

in the second embodiment of the present invention, S201 may specifically comprise steps of:

S2011, obtaining the output video frame and the fisheye image corresponding to the output video frame;

S2012, obtaining the timestamp t_(frame) ^(k) ^(p(x,y)) of the pixel p(x, y) in the k video frame in the time axis of a video frame acquisition system, where k is a natural number; and

S2013, obtaining the gyroscope timestamp t_(gyro) ^(k) ^(p(x,y)) in the time axis of the corresponding camera gyroscope acquisition system.

S202, synchronizing the timestamp of the pixel in the video frame to the camera gyroscope acquisition system, and calculating the rotation matrix of the camera movement in the timestamp of the pixel in the current video frame as the approximate rotation matrix of the camera when collecting the current pixel;

in the second embodiment of the present invention, S202 may specifically include the following steps:

S2021, synchronizing the timestamp of the pixel in the video frame to the camera gyroscope acquisition system, the conversion relationship between the two as shown in formula (8):

t _(gyro) ^(k) =ΔT ₀ +t _(frame) ^(k)  (8)

in formula (8), ΔT₀=t_(gyro) ^(k)−t_(frame) ^(k), t_(gyro) ^(k) is the camera gyroscope timestamp at the beginning of the k video frame, and t_(frame) ^(k) is the timestamp of the pixel at the beginning of the k video frame;

S2022, calculating a rotation matrix of the camera movement under the timestamp of the pixel in the current video frame at time t_(gyro) ^(k) by formula (9):

R _(w2s)(t _(gyro) ^(k))=R _(w2g)(t _(gyro) ^(k))·R _(g2s)(t _(gyro) ^(k))  (9)

in formula (9), R_(w2g)(t_(gyro) ^(k)) is the rotation matrix measured by the gyroscope sensor at time t_(gyro) ^(k), R_(w2g)(t_(gyro) ^(k)) is a 3*3 matrix; and R_(g2s)(t_(gyro) ^(k)) is the rotation matrix from the calibrated gyroscope coordinate system to the camera.

S203, projecting the output video frame pixels to the corresponding grid points of the spherical model, and using the approximate rotation matrix to rotate the corresponding grid points of the spherical model to the grid points in the sensor coordinate system; using the fisheye image distortion correction method to establish the relationship between the grid points in the sensor coordinate system and the pixels in the fisheye image to obtain approximate reverse-mapping pixels;

in the second embodiment of the present invention, S203 may specifically be:

where let

P^(s) = P_(t_(gyro)^(k_(p(x, y))))^(s),

obtaining a panoramic expanded image of P^(s) in the camera coordinate system:

${P^{s} = \left\{ \begin{matrix} {{\cos (u)}{\cos (v)}} \\ {{\cos (u)}{\sin (v)}} \\ {\sin (u)} \end{matrix} \right.},$

where u and v are the abscissa and ordinate of the panoramic expanded image in the camera coordinate system, respectively;

a fisheye distortion model ρ=f(θ)=θ(1+k₀θ²+k₁θ⁴+k₂θ⁶+k₃θ⁸), where θ is an incident angle of the light, k₀, k₁, k₂, and k₃ are the camera calibration coefficients, obtaining the corrected coordinates (x, y) of the fisheye image:

$\quad\left\{ \begin{matrix} {x = {{f_{x}{\bullet\rho\bullet}\frac{P_{x}^{s}}{r}} + x_{c}}} \\ {y = {{f_{y}{\bullet\rho\bullet}\frac{P_{y}^{s}}{r}} + y_{c}}} \end{matrix} \right.$

where r=√{square root over (P_(x) ^(s2)+P_(y) ^(s2))} and θ=atan(r, P_(z) ^(s)); the point (x_(c), y_(c)) is a projection center of the sensor, x and y are the 2D coordinates of the projection position of the camera sensor respectively.

S204, calculating the camera gyroscope timestamp of the approximate reverse-mapping pixels in the fisheye image, obtaining the accurate rotation matrix of the camera when collecting the current pixel, and using the accurate is rotation matrix to rotate the corresponding grid points of spherical model again to obtain the second grid points in the sensor coordinate system;

in the second embodiment of the present invention, the step of calculating the camera gyroscope timestamp of the approximate reverse-mapping pixels in the fisheye image, obtaining the accurate rotation matrix of the camera motion when collecting the current pixel, specifically is:

using the approximate reverse-mapping pixels in the fisheye image to calculate the camera gyroscope timestamp of the pixel by the formula:

$\begin{matrix} {t_{gyro}^{k_{p{({x,y})}}} = {{\Delta T_{0}} + t_{frame}^{k_{p{({x,y})}}} + {\frac{\Delta t}{H}y} - {\frac{1}{2}\Delta t}}} & (10) \end{matrix}$

in formula (10), Δt is a sampling time interval of the progressive scan of the video frame, and H is the number of lines of the image;

further calculating the accurate rotation matrix R_(w2s)(t_(gyro) ^(k) ^(p(x,y)) ) of the camera motion under the camera gyroscope timestamp, where the calculation formula is:

R _(w2s)(t _(gyro) ^(k) ^(p(x,y)) )=R _(w2g)(t _(gyro) ^(k) ^(p(x,y)) )·R _(g2s)(t _(gyro) ^(k) ^(p(x,y)) ).

S205, using the fisheye image distortion correction method to establish the relationship between the second grid points in the sensor coordinate system and the pixels in the fisheye image to obtain accurate pixels in the fisheye image, and using the mapping relationship between the output video frame pixels and the accurate pixels in the fisheye image, rendering the fisheye image in reverse rendering to generate a stable video.

Referring to FIG. 5, in the second embodiment of the present invention:

projecting the output video frame pixel A₄ to the corresponding grid point A₃ of the spherical model, using the approximate rotation matrix to rotate A₃ to obtain A₂ in the sensor coordinate system, using the fisheye image distortion correction method to project A₂ onto the fisheye image to obtain the pixel A₁, using the accurate rotation matrix to rotate A₁ to obtain A₂ in the sensor coordinate system, and then using the fisheye image distortion correction method to project A₂ to the fisheye image to obtain the accurate pixel A′₁; using the mapping relationship between the output video frame pixel A₄ and the accurate pixel A′₁ in the fisheye image to reverse map and render;

Similarly, projecting the output video frame pixel B₄ to the corresponding grid point B₃ of the spherical model, using the approximate rotation matrix to rotate B₃ to obtain B₂ in the sensor coordinate system, using the fisheye image distortion correction method to project B₂ onto the fisheye image to obtain pixel B₁, using the accurate rotation matrix to rotate B₁ to obtain B′₂ in the sensor coordinate system, and then using the fisheye image distortion correction method to project B₂ to the fisheye image to obtain the accurate pixel B′₁; using the mapping between the output video frame pixel B₄ and the accurate pixel B₁ in the fisheye image to reverse map and render;

It should also be noted that the perspective view generated by the projection or the color information of the asteroid image is input by interpolation, and finally a stable video can be generated.

In the second embodiment of the present invention, according to the timestamp of the video frame pixel, calculating the rotation matrix of the camera movement under the timestamp of the current video frame pixel as the approximate rotation matrix of the camera when collecting the current pixel, projecting the output video frame pixels to the corresponding grid points of the spherical model, and using the approximate rotation matrix to rotate the corresponding grid points of the is spherical model to the grid points in the sensor coordinate system; using the fisheye image distortion correction method to establish the relationship between the grid points in the sensor coordinate system and the pixels in the fisheye image to obtain approximate reverse-mapping pixels, calculating the camera gyroscope timestamp of the approximate reverse-mapping pixels in the fisheye image, obtaining the accurate rotation matrix of the camera when collecting the current pixel, and using the accurate rotation matrix to rotate the corresponding grid points of spherical model again to obtain the second grid points in the sensor coordinate system; using the fisheye image distortion correction method to establish the relationship between the second grid points in the sensor coordinate system and the pixels in the fisheye image to obtain accurate pixels in the fisheye image, and using the mapping relationship between the output video frame pixels and the accurate pixels in the fisheye image, rendering the fisheye image in reverse rendering to generate a stable video. Thereby, the distortion of the rolling shutter of the panoramic video sequence can be corrected.

The invention can correct the image distortion caused by the CMOS rolling shutter and eliminate the jelly effect, thereby achieve a better video image anti-shake effect.

Third Embodiment

The third embodiment of the present invention provides a computer-readable storage medium that stores a computer program or computer programs, which when being executed by a processor or processors, cause the processor or processors to perform steps of the anti-shake method for a panoramic video provided in the first or second embodiment of the present invention.

Fourth Embodiment

FIG. 6 shows a structural block diagram of a portable terminal provided in the fourth embodiment of the present invention. A portable terminal 100 comprises: one or more processors 101, a memory 102, and one or more computer programs, where the one or more processors 101 and the memory 102 are connected by a bus, the one or more computer programs are stored in the memory 102, and are configured to be is executed by the one or more processors 101. The one or more processors 101 execute the one or more computer programs to perform steps of the anti-shake method for a panoramic video provided in the first or second embodiment of the present invention.

A person of ordinary skill in the art may understand that all or part of the steps in the method of the above-mentioned embodiments can be implemented by a program or programs instructing relevant hardware. The program or programs can be stored in a computer-readable storage medium, and the storage media can be, such as ROM/RAM, magnetic disk, optical disk, etc.

The above descriptions are only preferred embodiments of the present invention and are not intended to limit the present invention. Any modification, equivalent replacements and improvement made within the spirit and principle of the present invention shall be included in the protection of the present invention. 

1. An anti-shake method for a panoramic video, comprising steps of: obtaining, in real time, an output video frame, a fisheye image corresponding to the output video frame, a timestamp of the pixel in the video frame, and a corresponding camera gyroscope timestamp; synchronizing the timestamp of the pixel in the video frame with the corresponding camera gyroscope timestamp, and calculating a rotation matrix of the camera movement in the camera gyroscope timestamp; smoothing the camera movement and establishing a coordinate system of a smooth trajectory; correcting the fisheye image distortion; and rendering the fisheye image by means of forward rendering to generate a stable video.
 2. The method of claim 1, wherein the step of obtaining, in real time, an output video frame, a fisheye image corresponding to the output video frame, a timestamp of the pixel in the video frame, and a corresponding camera gyroscope timestamp, specifically comprises: obtaining the output video frame and the fisheye image corresponding to the output video frame; obtaining the timestamp t_(frame) ^(k) ^(p(x,y)) of the pixel p(x, y) in the k video frame in the time axis of a video frame acquisition system, where k is a natural number; and obtaining the gyroscope timestamp t_(gyro) ^(k) ^(p(x,y)) in the time axis of the corresponding camera gyroscope acquisition system.
 3. The method of claim 2, wherein the step of synchronizing the timestamp of the pixel in the video frame with the corresponding camera gyroscope timestamp, and calculating a rotation matrix of the camera movement in the camera gyroscope timestamp, specifically comprises: calculating the timestamp t_(frame) ^(k) ^(p(x,y)) of the pixel p(x, y) in the k video frame by formula (1): $\begin{matrix} {{t_{frame}^{k_{p{({x,y})}}} = {t_{frame}^{k} + {\frac{\Delta t}{H}y} - {\frac{1}{2}\Delta \; t}}};} & (1) \end{matrix}$ in formula (1), t_(frame) ^(k) is the timestamp of the pixel at the beginning of the k video frame, Δt is a sampling time interval of the progressive scan of the video frame, and H is the number of lines of the image; synchronizing the timestamp of the pixel in the k video frame with the camera gyroscope timestamp, a conversion relationship between the two as formula (2): t _(gyro) ^(k) ^(p(x,y)) P(″Y)=ΔT ₀ +t _(frame) ^(k) ^(p(x,y))   (2) in formula (2), ΔT₀=t_(gyro) ^(k)−t_(frame) ^(k), t_(gyro) ^(k) the camera gyroscope timestamp at the beginning of the k video frame; and calculating a rotation matrix of the camera movement in the camera gyroscope timestamp at time t_(gyro) ^(k) ^(p(x,y)) by formula (3): R _(w2s)(t _(gyro) ^(k) ^(p(x,y)) )=R _(w2g)(t _(gyro) ^(k) ^(p(x,y)) )·R _(g2s)(t _(gyro) ^(k) ^(p(x,y)) )  (3) in formula (3), R_(w2g)(t_(gyro) ^(k) ^(p(x,y)) ) is a rotation matrix measured by a gyroscope sensor at time t_(gyro) ^(k) ^(p(x,y)) , and R_(g2s)(t_(gyro) ^(k) ^(p(x,y)) ) is a rotation matrix from the calibrated gyroscope coordinate system to the camera.
 4. The method of claim 3, wherein the step of smoothing the camera movement and establishing a coordinate system of a smooth trajectory, specifically comprises: where P^(s) representing the 3D coordinates in the camera coordinate system, let t=t_(gyro) ^(k) ^(p(x,y)) , converting the 3D coordinates P_(t) ^(w) in the world coordinate system to the 3D coordinates P_(t) ^(s) in the camera coordinate system at time t by a formula: P _(t) ^(s) =R _(w2s)(t)·P _(t) ^(w)+{right arrow over (t ₀)}  (4) in the formula (4), R_(w2s)(t) is a matrix of the camera coordinate system relative to the world coordinate system at time t, and {right arrow over (t₀)} is a translation amount of the two frames before and after of the video frame of the camera; smoothing the camera movement, where setting {right arrow over (t₀)}=0 and then obtaining ${P_{t}^{w} = \frac{P_{t}^{s}}{R_{w2s}(t)}};$ establishing a coordinate system P_(t)′ of a smooth trajectory, performing a 3D grid rendering processing on the coordinate system P_(t)′ of the camera's smooth trajectory by a rendering formula: P_(t) ^(gl)=K□R_(nvp)□P_(t)′; where K is a perspective matrix, R_(nvp) is a rotation matrix of the view direction manually controlled, and P_(t) ^(gl) is the 3D coordinates rendered in the coordinate system of the smooth trajectory; and in the coordinate system of the smooth trajectory, obtaining the minimum square difference of any pixel in P_(t)′ in the two frames before and after by a formula: min(P_(t+1)′−P_(t)′)²+(P_(t)′−P_(t) ^(w))², where P_(t)′ and P_(t+1)′ are the coordinate systems of the smooth trajectory of the two frames before and after, respectively; setting P_(t)′=P_(t+1)′=P_(t) ^(w), and obtaining the rendering formula as formula (5): P _(t) ^(gl) =K□R _(nvp) □R _(w2s(t)) ⁻¹ □P _(t) ^(s)  (5) calculating the 3D coordinates of the camera rendered to the coordinate system of the smooth trajectory by the formula (5).
 5. The method of claim 4, wherein the step of correcting the fisheye image distortion, specifically comprises: where let P^(s) = P_(t_(gyro)^(k_(p(x, y))))^(s),  obtaining a panoramic expanded image of P^(s) Ill in the camera coordinate system: $\begin{matrix} {P^{s} = \left\{ \begin{matrix} {{\cos (u)}{\cos (v)}} \\ {{\cos (u)}{\sin (v)}} \\ {\sin (u)} \end{matrix} \right.} & (6) \end{matrix}$ in formula (6), u and v are the abscissa and ordinate of the panoramic expanded image in the camera coordinate system, respectively; a fisheye distortion model ρ=f(θ)=θ(1+k₀θ²+k₁θ⁴+k₂θ⁶+k₃θ⁸), where θ is an incident angle of the light, k₀, k₁, k₂, and k₃ are the camera calibration coefficients, obtaining the corrected coordinates (x, y) of the fisheye image: $\begin{matrix} \left\{ \begin{matrix} {x = {{f_{x}{\bullet\rho\bullet}\frac{P_{x}^{s}}{r}} + x_{c}}} \\ {y = {{f_{y}{\bullet\rho\bullet}\frac{P_{y}^{s}}{r}} + y_{c}}} \end{matrix} \right. & (7) \end{matrix}$ in formula (7), r=√{square root over (P_(x) ^(s2)+P_(y) ^(s2))}, and θ=atan(r, P_(z) ^(s)); the point (x_(c), y_(c)) is a projection center of the sensor, x and y are the 2D coordinates of a projection position of the camera sensor respectively.
 6. The method of claim 5, wherein the step of rendering the fisheye image by means of forward rendering to generate a stable video, specifically comprises: establishing a correspondence between the fisheye image and grid points of the spherical model in the camera coordinate system by means of a fisheye image distortion correction method; generating grid points of the spherical model in the coordinate system of the smooth trajectory by rendering; and performing panoramic expansion for the grid points of the spherical model in the coordinate system of the smooth trajectory to generate a stable video.
 7. A non-transitory computer-readable medium that stores one or more computer programs including a set of computer-executable instructions, wherein when being executed by one or more processors, cause the one or more processors to perform steps of the anti-shake method for a panoramic video of claim
 1. 8. A portable terminal, comprising: one or more processors; a memory; and one or more computer programs including a set of computer-executable instructions, where the set of computer-executable instructions are stored in the memory and are configured to be executed by the one or more processors, wherein when being executed by the one or more processors, cause the one or more processors to perform steps of an anti-shake method for a panoramic video: obtaining, in real time, an output video frame, a fisheye image corresponding to the output video frame, a timestamp of the pixel in the video frame, and a corresponding camera gyroscope timestamp; synchronizing the timestamp of the pixel in the video frame with the corresponding camera gyroscope timestamp, and calculating a rotation matrix of the camera movement in the camera gyroscope timestamp; smoothing the camera movement and establishing a coordinate system of a smooth trajectory; correcting the fisheye image distortion; and rendering the fisheye image by means of forward rendering to generate a stable video.
 9. An anti-shake method for a panoramic video, comprising steps of: S201, obtaining, in real time, an output video frame, a fisheye image corresponding to the output video frame, a timestamp of the pixel in the video frame, and a corresponding camera gyroscope timestamp; S202, synchronizing the timestamp of the pixel in the video frame to the corresponding camera gyroscope acquisition system, and calculating a rotation matrix of the camera movement in the timestamp of the pixel in the current video frame, as an approximate rotation matrix of the camera when collecting the current pixel; S203, projecting the output video frame pixels to the corresponding grid points of the spherical model, and using the approximate rotation matrix to rotate the corresponding grid points of the spherical model to the grid points in the sensor coordinate system; using a fisheye image distortion correction method to establish a relationship between the grid points in the sensor coordinate system and the pixels in the fisheye image to obtain approximate reverse-mapping pixels; S204, calculating the camera gyroscope timestamp of the approximate reverse-mapping pixels in the fisheye image, obtaining the accurate rotation matrix of the camera when collecting the current pixel, and using the accurate rotation matrix to rotate the corresponding grid points of spherical model again to obtain the second grid points in the sensor coordinate system; and S205, using the fisheye image distortion correction method to establish the relationship between the second grid points in the sensor coordinate system and the pixels in the fisheye image to obtain accurate pixels in the fisheye image, and using a mapping relationship between the output video frame pixels and the accurate pixels in the fisheye image, rendering the fisheye image in reverse rendering to generate a stable video.
 10. The method of claim 9, wherein S201 specifically comprises: obtaining the output video frame and the fisheye image corresponding to the output video frame; obtaining of the timestamp t_(frame) ^(k) ^(p(x,y)) of the pixel p(x, y) in the k video frame in the time axis of a video frame acquisition system, where k is a natural number; and obtaining the gyroscope timestamp t_(gyro) ^(k) ^(p(x,y)) in the time axis of the corresponding camera gyroscope acquisition system.
 11. The method of claim 10, wherein S202 specifically comprises steps: synchronizing the timestamp of the pixel in the video frame to the corresponding camera gyroscope acquisition system, a conversion relationship between the two as shown in formula (8): t _(gyro) ^(k) =ΔT ₀ +t _(frame) ^(k)  (8) where in formula (8), ΔT₀=t_(gyro) ^(k)−t_(frame) ^(k)t_(gyro) ^(k) is the camera gyroscope timestamp at the beginning of the k video frame, and t_(frame) ^(k) is the timestamp at the beginning of the k video frame; and calculating a rotation matrix of the camera movement under the timestamp of the pixel in the current video frame at time t_(gyro) ^(k) by formula (9): R _(w2s)(t _(gyro) ^(k))=R _(w2g)(t _(gyro) ^(k))·R _(g2s)(t _(gyro) ^(k))  (9) where in formula (9), R_(w2g)(t_(gyro) ^(k)) is a rotation matrix measured by the gyroscope sensor at time t_(gyro) ^(k), and R_(g2s)(t_(gyro) ^(k)) is a rotation matrix from the calibrated gyroscope coordinate system to the camera.
 12. The method of claim 11, wherein S203 is that: where let P^(s) = P_(t_(gyro)^(k_(p(x, y))))^(s),  obtaining a panoramic expanded image of P^(s) in the camera coordinate system: ${P^{s} = \left\{ \begin{matrix} {{\cos (u)}{\cos (v)}} \\ {{\cos (u)}{\sin (v)}} \\ {\sin (u)} \end{matrix} \right.},$  where u and v are the abscissa and ordinate of the panoramic expanded image in the camera coordinate system, respectively; a fisheye distortion model ρ=f(θ)+θ(1+k₀θ²+k₁θ⁴+k₂θ⁶+k₃θ⁸), where θ is an incident angle of the light, k₀, k₁, k₂, and k₃ are the camera calibration coefficients, obtaining the corrected coordinates (x, y) of the fisheye image: $\left\{ {\begin{matrix} {x = {{f_{x}{\bullet\rho\bullet}\frac{P_{x}^{s}}{r}} + x_{c}}} \\ {y = {{f_{y}{\bullet\rho\bullet}\frac{P_{y}^{s}}{r}} + y_{c}}} \end{matrix},} \right.$ where r=√{square root over (P_(x) ^(s2)+P_(y) ^(s2))} and θ=atan(r, P_(z) ^(s)); the point (x_(c), y_(c)) is a projection center of the sensor, x and y are the 2D coordinates of a projection position of the camera sensor respectively.
 13. The method of claim 12, wherein the step of calculating the camera gyroscope timestamp of the approximate reverse-mapping pixels in the fisheye image, obtaining the accurate rotation matrix of the camera motion when collecting the current pixel, specifically is: using the approximate reverse-mapping pixels in the fisheye image to calculate the camera gyroscope timestamp of the pixel by the formula: $\begin{matrix} {t_{gyro}^{k_{p{({x,y})}}} = {{\Delta T_{0}} + t_{frame}^{k_{p{({x,y})}}} + {\frac{\Delta t}{H}y} - {\frac{1}{2}\Delta t}}} & (10) \end{matrix}$ where in formula (10), Δt is a sampling time interval of the progressive scan of the video frame, and H is the number of lines of the image; then calculating the accurate rotation matrix R_(w2s)(t_(gyro) ^(k) ^(p(x,y)) ) of the camera motion under the camera gyroscope timestamp, where the calculation formula is: R _(w2s)(t _(gyro) ^(k) ^(p(x,y)) =R _(w2g)(t _(gyro) ^(k) ^(p(x,y)) )·R _(g2s)(t _(gyro) ^(k) ^(p(x,y)) ).
 14. The method of claim 13, wherein S205 specifically is: projecting the output video frame pixel A₄ to the corresponding grid point A₃ of the spherical model, using the approximate rotation matrix to rotate A₃ to obtain A₂ in the sensor coordinate system, using the fisheye image distortion correction method to project A₂ onto the fisheye image to obtain the pixel A₁, using the accurate rotation matrix to rotate A₁ to obtain A′₂ in the sensor coordinate system, and then using the fisheye image distortion correction method to project A′₂ to the fisheye image to obtain the accurate pixel A′₁; using the mapping relationship between the output video frame pixel A₄ and the accurate pixel A′₁ in the fisheye image to render the fisheye image in reverse rendering to generate a stable video; similarly, projecting the output video frame pixel B₄ to the corresponding grid point B₃ of the spherical model, using the approximate rotation matrix to rotate B₃ to obtain B₂ in the sensor coordinate system, using the fisheye image distortion correction method to project B₂ onto the fisheye image to obtain pixel B₁, using the accurate rotation matrix to rotate B₁ to obtain B′₂ in the sensor coordinate system, and then using the fisheye image distortion correction method to project B′₂ to the fisheye image to obtain the accurate pixel B′₁; using the mapping relationship between the output video frame pixel B₄ and the accurate pixel B′₁ in the fisheye image to render the fisheye image in reverse rendering to generate a stable video.
 15. A non-transitory computer-readable medium that stores one or more computer programs including a set of computer-executable instructions, wherein when being executed by one or more processors, cause the one or more processors to perform steps of the anti-shake method for a panoramic video of claim
 9. 16. A portable terminal, comprising: one or more processors; a memory; and one or more computer programs including set of computer-executable instructions, where the set of computer-executable instructions are stored in the memory and are configured to be executed by the one or more processors, wherein being executed by the one or more processors execute, cause the one or more processors to perform steps of the anti-shake method for a panoramic video of claim
 9. 